<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$return['params']=$params=array('uniacid'=>$_SESSION['uniacid'],);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(isset($_RQ['is_add'])){
		$params['is_add']=intval($_RQ['is_add']);
		$return['params']['is_add']=$_RQ['is_add'];
	}
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['createtime']=$time_range;
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array();
	$list=pdo_getslice('jy_jdpm_credit_log',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			
			$item['account']=pdo_getcolumn('jy_jdpm_member',array('mid'=>$item['mid']),'account');
			$item['account']=$item['account']?$item['account']:'无';
		}
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['list']=$list;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'积分记录'),
		),
		'export'=>'export',
		'export_title'=>'导出积分日志',
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('type'=>'string','title'=>'用户UID','name'=>'mid','help'=>''),
			array('name'=>'account','title'=>'用户账号','type'=>'string'),
			
			array('name'=>'fee','title'=>'积分','type'=>'string'),
			array('name'=>'createtime','title'=>'变动时间','type'=>'string'),
			array('name'=>'is_add','title'=>'类型','type'=>'radio','options'=>'is_add'),
			
			array('name'=>'remark','title'=>'备注','type'=>'string'),
			
			
		
		),
		
		),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'用户UID','name'=>'mid','help'=>''),
			array('type'=>'select','width'=>'15','title'=>'类型','name'=>'is_add','help'=>'','options'=>'is_add2','select_title'=>'请选择类型'),
			array('type'=>'time_range','width'=>'16','title'=>'申请时间','name'=>'createtime','help'=>''),
		),
	);
	
	$return['is_add']=array('1'=>'增加','0'=>'减少');
	$return['is_add2']=array(array('id'=>1,'title'=>'增加'),array('id'=>0,'title'=>'减少'));
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export'){
	$params=array('uniacid'=>$_SESSION['uniacid'],);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
	}
	if(isset($_RQ['is_add'])){
		$params['is_add']=intval($_RQ['is_add']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array();
	$list=pdo_getall('jy_jdpm_credit_log',$params,$fields,'','createtime desc');
	if($list){
		$is_adds=array('1'=>'增加','0'=>'减少');
		foreach($list as &$item){
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			
			$item['account']=pdo_getcolumn('jy_jdpm_member',array('mid'=>$item['mid']),'account');
			$item['account']=$item['account']?$item['account']:'无';
			$item['is_add']=$is_adds[$item['is_add']];
		}
	}
	$header=array(
		'mid'=>'用户UID',
		'account'=>'用户账号',
		'fee'=>'积分',
		'createtime'=>'变动时间',
		'is_add'=>'类型',
		'remark'=>'备注',
	);
	cfc('tools')->export2excel($header,$list,'积分日志');
}